<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>权限管理</title>
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <link rel="stylesheet" href="/layuiAdmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiAdmin/css/admin.css" media="all">
</head>

<body>


<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">权限名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input" id="name">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search" id="search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-useradmin" data-type="batchdel" id="del">删除</button>
                <button class="layui-btn layuiadmin-btn-useradmin" data-type="add" id="create" data-url="/admin/auth/create">添加</button>
            </div>


            <table class="layui-table" lay-data="{url:'/admin/auth', page:true, limit:90, id:'test',height: 'full-25'}" lay-filter="test" id="test">
                <thead>
                <tr>
                    <th lay-data="{checkbox:true}"></th>
                    <th lay-data="{field:'id', width:80, sort: true}">ID</th>
                    <th lay-data="{field:'name', width:190, sort: true}">权限模块</th>
                    <th lay-data="{field:'allChildAuth', width:1250 , templet: '#allChildAuth'}">权限</th>
                    <th lay-data="{width:200, templet: '#table-useradmin-webuser'}">操作</th>
                </tr>
                </thead>
            </table>
            <script type="text/html" id="table-useradmin-webuser">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"  data-url="/admin/auth/edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>

            <script type="text/html" id="allChildAuth">
                @verbatim
                {{#  for(var i=0;i<d.allChildAuth.length;i++){ }}
                <a href="/admin/auth/edit/{{ d.allChildAuth[i].id }}" class="layui-table-link" style="margin-right: 20px">{{ d.allChildAuth[i].name }}</a>
                {{#  }; }}
                @endverbatim
            </script>
        </div>
    </div>
</div>
<script src="/layuiAdmin/layui/layui.js"></script>
<script src="/layuiAdmin/tool.js"></script>
<script>
    layui.use(['table','form'], function() {
        var table = layui.table ;
        var $ = layui.jquery,
            layer = layui.layer,
            form = layui.form;

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        var active = {
            dels: function(){
                var checkStatus = table.checkStatus('test')
                    ,data = checkStatus.data;
                var ids = [];
                for(var index in data){
                    ids.push(data[index].id);
                }

                $.post('/admin/auth/destroy',{id:ids}, function (rJson) {
                    if(rJson.status){
                        layer.msg(rJson.msg, {time: 5000, icon:6});
                        reload();
                    }else {
                        layer.msg(rJson.msg, {time: 5000, icon:5});
                    }
                })
            }
        };

        $('#del').on('click',function () {
            active['dels'].call(this);
        });



        //监听工具条
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                $.post('/admin/auth/destroy',{id:data.id}, function (rJson) {
                    if(rJson.status){
                        layer.msg(rJson.msg, {time: 5000, icon:6});
                        obj.del();
                    }else {
                        layer.msg(rJson.msg, {time: 5000, icon:5});
                    }
                })
            } else if(obj.event === 'edit'){
                location.href='/admin/auth/edit/' + data.id;
            }
        });


        $('#create').click(function(){
            var url = $(this).data('url');
            $('#LAY_app_body iframe', window.parent.document).attr('src', url);
        });

        $('#search').click(function () {
            reload();
        });


        function reload() {
            table.reload('test', {
                url: '/admin/auth'
                ,where: {
                    name : $('#name').val(),
                }
                ,page: {
                    curr: 1
                }
            });
        }

    });
</script>
</body>

</html>